package cn.zhaoyun.controller;

import cn.zhaoyun.entity.Emp;
import cn.zhaoyun.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class EmpController {
    @Autowired
    private EmpService service;

    @RequestMapping("/findById/{id}")
    public Emp findById(@PathVariable("id") Long id) {
        System.out.println("controller收到查询请求(by id): " + id);
        Emp e = service.findById(id);
        return e;
    }

    @RequestMapping("/update")
    public Emp update(Emp emp) {
        System.out.println("controller收到更新请求: " + emp);
        return service.update(emp);
    }

    @RequestMapping("/delete/{id}")
    public String delete(@PathVariable("id") Long id) {
        System.out.println("controller收到删除请求: " + id);
        service.delete(id);
        return "delete success";
    }

    @RequestMapping("/findByName/{name}")
    public Emp findByName(@PathVariable("name") String name) {
        System.out.println("controller收到查询请求(by name): " + name);
        return service.findByName(name);
    }
}
